/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "optionmenu")
@NamedQueries({
    @NamedQuery(name = "Option.findAll", query = "SELECT o FROM Option o"),
    @NamedQuery(name = "Option.findByMenuId", query = "SELECT o FROM Option o WHERE o.optionPK.menuId = :menuId"),
    @NamedQuery(name = "Option.findBySubmenuId", query = "SELECT o FROM Option o WHERE o.optionPK.submenuId = :submenuId"),
    @NamedQuery(name = "Option.findByMenuIdBySubmenuId", query = "SELECT o FROM Option o WHERE o.optionPK.menuId = :menuId AND o.optionPK.submenuId = :submenuId"),
    @NamedQuery(name = "Option.findByOptionId", query = "SELECT o FROM Option o WHERE o.optionPK.optionId = :optionId"),
    @NamedQuery(name = "Option.findByMenuIdBySubmenuIdByOptionId", query = "SELECT o FROM Option o WHERE o.optionPK.menuId = :menuId AND o.optionPK.submenuId = :submenuId AND o.optionPK.optionId = :optionId"),
    @NamedQuery(name = "Option.findByName", query = "SELECT o FROM Option o WHERE o.name = :name"),
    @NamedQuery(name = "Option.findByUrl", query = "SELECT o FROM Option o WHERE o.url = :url"),
    @NamedQuery(name = "Option.findByOrder", query = "SELECT o FROM Option o WHERE o.order = :order")})
public class Option implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected OptionPK optionPK;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Column(name = "url")
    private String url;
    @Basic(optional = false)
    @Column(name = "order")
    private short order;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "option")
    private Collection<Defaultaccess> defaultaccessCollection;
    @JoinColumns({
        @JoinColumn(name = "menuId", referencedColumnName = "menuId", insertable = false, updatable = false),
        @JoinColumn(name = "submenuId", referencedColumnName = "submenuId", insertable = false, updatable = false)})
    @ManyToOne(optional = false)
    private Submenu submenu;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "option")
    private Collection<Access> accessCollection;

    public Option() {
    }

    public Option(OptionPK optionPK) {
        this.optionPK = optionPK;
    }

    public Option(OptionPK optionPK, String name, short order) {
        this.optionPK = optionPK;
        this.name = name;
        this.order = order;
    }

    public Option(short menuId, short submenuId, short optionId) {
        this.optionPK = new OptionPK(menuId, submenuId, optionId);
    }

    public OptionPK getOptionPK() {
        return optionPK;
    }

    public void setOptionPK(OptionPK optionPK) {
        this.optionPK = optionPK;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public short getOrder() {
        return order;
    }

    public void setOrder(short order) {
        this.order = order;
    }

    public Collection<Defaultaccess> getDefaultaccessCollection() {
        return defaultaccessCollection;
    }

    public void setDefaultaccessCollection(Collection<Defaultaccess> defaultaccessCollection) {
        this.defaultaccessCollection = defaultaccessCollection;
    }

    public Submenu getSubmenu() {
        return submenu;
    }

    public void setSubmenu(Submenu submenu) {
        this.submenu = submenu;
    }

    public Collection<Access> getAccessCollection() {
        return accessCollection;
    }

    public void setAccessCollection(Collection<Access> accessCollection) {
        this.accessCollection = accessCollection;
    }
/*
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (optionPK != null ? optionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Option)) {
            return false;
        }
        Option other = (Option) object;
        if ((this.optionPK == null && other.optionPK != null) || (this.optionPK != null && !this.optionPK.equals(other.optionPK))) {
            return false;
        }
        return true;
    }

    @Override	*/
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Option[ optionPK=" + optionPK + " ]";
    }
    
}
